// 
// Bachelor of Software Engineering
// Media Design School
// Auckland
// New Zealand
//
// (c) 2005 - 2014 Media Design School
//
// File Name	: WinMain.cpp
// Desrciption	: WinMain implementation file.
// Author(s)	: Hayden Asplet.
// Mail			: hayden.asplet@mediadesignschool.com
//


// PCH
#include "GameStd.h"

// Library Includes
#include <ctime>

// Local Includes
#include "GameBase\GameApp.h"
#include "Utilities\Console\Console.h"

// Namespaces
using namespace std;
/*#ifndef _USE_OLD_OSTREAMS

	using namespace std;

#endif*/


//---------------------------------------------------------
// WinMain() is the entry point to the application.
//
// It triggers the initialization sequence and enters a 
// message processing loop. Giving control to the CGameApp.
//---------------------------------------------------------

int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE _hPrevInstance, LPSTR _lpCmdLine, int _nCmdShow)
{
	// Redirect console information when in debug (JG)
	#ifdef _DEBUG
		RedirectIOToConsole();
		cout << "DEBUG: Console Loaded" << endl;
	#endif

	srand(unsigned(time(0))); // Seed the random generator

	MSG msg;

	ZeroMemory(&msg, sizeof(msg));

	// Perform the initialization sequence.
	if(!g_pApp->VInitialize(_hInstance, _lpCmdLine)) {
	// Failed to initialize.
		return 0;
	}

	while(msg.message != WM_QUIT && g_pApp->IsRunning()) {
		if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
			// Translate any accelerator keys...
			TranslateMessage(&msg);

			// Send the message to the window proc.
			DispatchMessage(&msg);
		}
		else {
			// Update the game.
			g_pApp->Update();
		}
	}

	// Return to windows.
	return static_cast<int>(msg.wParam);
}